﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransCend.DB;
using TransCend.Model;
using TransCend.Util.Page;

namespace TransCend.DAL
{
    public interface ICommonDAL
    {
        Column GetColumn(string tablename, string columnname);

        T FindByID<T>(int id) where T : BaseModel;

        /// <summary>
        /// 单个字段条件获取唯一记录对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        T FindByProperty<T>(string propertyname, object propertyvalue) where T : BaseModel;

        T FindByPropertys<T>(string[] propertynames, object[] propertyvalues) where T : BaseModel;

        int Insert<T>(T model) where T : BaseModel;

        int InsertReturnId<T>(T mode) where T : BaseModel;

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Insert<T>(IList<T> models) where T : BaseModel;

        int Update<T>(T model) where T : BaseModel;

        int Delete<T>(int id) where T : BaseModel;

        /// <summary>
        /// 单个字段删除记录
        /// </summary>
        /// <typeparam name="int"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        int DeleteByProperty<T>(string propertyname, object propertyvalue) where T : BaseModel;

        /// <summary>
        /// 多个字段删除记录
        /// </summary>
        /// <typeparam name="int"></typeparam>
        /// <param name="propertynames"></param>
        /// <param name="propertyvalues"></param>
        /// <returns></returns>
        int DeleteByPropertys<T>(string[] propertynames, object[] propertyvalues) where T : BaseModel;
        /// <summary>
        /// 对主键为string类型的ID删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        int Delete<T>(string id) where T : BaseModel;

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ids"></param>
        /// <returns></returns>
        int Delete<T>(int[] ids) where T : BaseModel;

        int Delete<T>(string DBFied, object value) where T : BaseModel;

        /// <summary>
        /// 只更新DBFields中的字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="DBFields"></param>
        /// <returns></returns>
        int UpdatePartially<T>(T model, string[] DBFields) where T : BaseModel;

        /// <summary>
        /// 对DBField字段计数，默认+1
        /// </summary>
        /// <param name="id"></param>
        /// <param name="DBField"></param>
        /// <returns></returns>
        int UpdateSetp<T>(int id, string DBField) where T : BaseModel;

        /// <summary>
        /// 对DBField字段计数，增+setp
        /// </summary>
        /// <param name="id"></param>
        /// <param name="DBField"></param>
        /// <param name="setp"></param>
        /// <returns></returns>
        int UpdateSetp<T>(int id, string DBField, int setp) where T : BaseModel;

        /// <summary>
        /// 合并，不更新model空值字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Merge<T>(T model) where T : BaseModel;

        /// <summary>
        /// 所有数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IList<T> FindAll<T>(params OrderBy[] orderBy) where T : BaseModel;

        /// <summary>
        /// 根据单个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        IList<T> FindList<T>(string propertyname, object propertyvalue, params OrderBy[] orderBy) where T : BaseModel;

        /// <summary>
        /// 多个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertynames"></param>
        /// <param name="propertyvalues"></param>
        /// <returns></returns>
        IList<T> FindList<T>(string[] propertynames, object[] propertyvalues, params OrderBy[] orderBy) where T : BaseModel;

        /// <summary>
        /// 多个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryModel">不为空的为查询条件</param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        IList<T> FindList<T>(T queryModel, params OrderBy[] orderBy) where T : BaseModel;

        /// <summary>
        /// 多个条件查询列表数据数量
        /// </summary>
        int FindListCount<T>(T queryModel) where T : BaseModel;

        IList<T> FindList<T>(int[] ids, params OrderBy[] orderBy) where T : BaseModel;

        PageTools<T> FindPage<T>(int page, int rows, OrderBy[] orderBy) where T : BaseModel;

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="queryModel">不为空的为查询条件</param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        PageTools<T> FindPage<T>(int page, int rows, T queryModel, OrderBy[] orderBy) where T : BaseModel;

        /// <summary>
        /// 获取数据库当前时间
        /// </summary>
        /// <returns></returns>
        DateTime FindNowDate();
    }
}
